<?php

/* @project : Template
 * @auther  : 大梦
 * @date    : 2020/12/08
 * @desc    : 部门信息
 */

namespace app\common\model;

class Department extends Base
{
    protected $autoWriteTimestamp = true;

    /**
     * 获取部门信息
     * @author Meng
     * @dateTime 2020-12-09
     * @return   [type]     [description]
     */
    public function getDepartmentList()
    {
        $where_dept = [
            ['is_valid', 'eq', 1],
            ['is_del', 'eq', 0],
        ];
        $list    = $this->where($where_dept)->order('id asc')->order('sort asc')->select();
        return $list->toArray();
    }

    /**
     * 根据部门获取用户
     * @author Meng
     * @dateTime 2020-12-09
     * @param    [type]     $dept_no [description]
     * @return   [type]              [description]
     */
    public function getStaffIdListByDeptId($dept_no)
    {
        $where_dept = [
            ['is_valid', 'eq', 1],
            ['is_del', 'eq', 0],
        ];
        $dept_pid = $this->where($where_dept)->where('id', 'eq', $dept_no)->order('id asc')->order('sort asc')->value('pid');
        $dept_ids[] = $dept_no;
        if ($dept_pid < 1) {
            $dept_ids = $this->where($where_dept)->where('id|pid', 'eq', $dept_no)->order('id asc')->order('sort asc')->column('id');
        }
        $where[] = ['dept_no', 'in', $dept_ids];
        $StaffModel = new Staff();
        $list    = $StaffModel->where($where)->column('id');
        return $list;
    }

}
